package pe.com.hermes.hermetic.web.controller.autenticacion;

import pe.com.hermes.hermetic.beans.ClienteBean;
import pe.com.hermes.hermetic.negocio.service.HermeticFacade;
import pe.com.hermes.hermetic.negocio.service.TablService;
import pe.com.hermes.hermetic.negocio.ultil.Browser;
import pe.com.hermes.hermetic.negocio.ultil.Util;
import pe.com.hermes.hermetic.web.forms.AutenticarForm;



import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import javax.validation.Valid;

import org.apache.log4j.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@RequestMapping("/login.html")
@Controller
public class AutenticarController {
    private final static String FORM_LOGIN_VIEW = ".login";
    private final static String FORM_HOME_VIEW = ".bienvenida";
    private final static String FORM_MOZILLA_VIEW = ".errorMozilla";
    private final static String FORM_KEY = "form";     
    private Logger logger = Logger.getLogger(this.getClass());
    private static long transLogeo = 0;
    @Autowired
    private HermeticFacade servicioHermetic;
    @Autowired
    private TablService tablService;
    @Autowired
    private UserDetailsService userDetailsService;
    
    @RequestMapping(method=RequestMethod.GET)
    protected String showForm(ModelMap model,HttpServletRequest request,HttpServletResponse response) throws Exception{
        HttpSession session = request.getSession(true);
        Browser browser = new Browser(request, session);
        String navegador = browser.getName();
        if (!(navegador.indexOf("Microsoft") > -1)) {
            return FORM_MOZILLA_VIEW;
        }
        model.put(FORM_KEY,new AutenticarForm());
        return FORM_LOGIN_VIEW;
    }
}
